import { cloneDeep } from 'lodash'
import { getRole } from '@/utils/user'
export default {
  namespaced: true,
  // 静态角色鉴权的侧边栏信息
  state: {
    menus: [
      {
        label: '首页',
        icon: 'Odometer',
        path: 'dashBoard',
        ismenu: false,
        roles: '*'
      },
      {
        label: '资产管理',
        icon: 'Trophy',
        ismenu: true,
        roles: ['admin', 'a', 'b'],
        children: [
          {
            label: '商品区管理',
            icon: 'ChromeFilled',
            path: 'tradeMsg',
            ismenu: false,
            roles: ['admin', 'a', 'b']
          },
          {
            label: '楼栋管理',
            icon: 'OfficeBuilding',
            path: 'towerMsg',
            ismenu: false,
            roles: ['admin', 'a', 'b']
          }
        ]
      },
      {
        label: '收费设置',
        icon: 'Edit',
        ismenu: true,
        roles: ['admin', 'a', 'b'],
        children: [
          {
            label: '收费项管理',
            icon: 'Grid',
            path: 'getMoney',
            ismenu: false,
            roles: ['admin', 'a', 'b']
          },
          {
            label: '租赁合同管理',
            icon: 'Memo',
            path: 'contractMsg',
            ismenu: false,
            roles: ['admin', 'a', 'b']
          }
        ]
      },
      {
        label: '系统设置',
        icon: 'Setting',
        path: 'setMsg',
        ismenu: false,
        roles: ['a', 'b']
      }
    ]
  },
  getters: {
    // 过滤侧边栏信息
    newsMenus (state) {
      const role = getRole()
      const newsMenus = []
      const newState = cloneDeep(state.menus)
      newState.forEach((menus) => {
        if (menus.roles === '*' || menus.roles.includes(role)) {
          if (menus.ismenu) {
            menus.children.filter((item) => {
              return menus.roles === '*' || menus.roles.includes(role)
            })
          }
          newsMenus.push(menus)
        }
      })
      return newsMenus
    }
  }
}
